package com.jiaai.push;

import com.alibaba.dubbo.config.annotation.Reference;
import com.jiaai.push.api.IWarnApi;
import com.jiaai.push.model.TWarnVO;
import com.jiaai.util.RestResultGenerator;
import org.springframework.web.bind.annotation.*;

/**
 * Created by Administrator on 2018/1/3.
 */
@RestController
@RequestMapping("/api/v1/admin/warn")
public class warnController {

        @Reference
        private IWarnApi iWarnApi;

        @PostMapping("/add")
        public Object pushMessage(@RequestBody TWarnVO tWarnVO) throws Exception{
                try {
                        iWarnApi.add(tWarnVO);
                        return RestResultGenerator.genSuccessResult("添加成功");
                } catch (Exception e) {
                        return RestResultGenerator.genErrorResult("添加失败");
                }

        }
        @GetMapping("/all")
        public  Object warnAll(Integer curr,TWarnVO tWarnVO) throws Exception{
                try {
                        return RestResultGenerator.genSuccessResult(iWarnApi.warnAll(curr,tWarnVO));
                } catch (Exception e) {
                        return RestResultGenerator.genErrorResult("查询失败");
                }
        }


        @GetMapping("/finAll")
        public  Object finAll(TWarnVO tWarnVO) throws Exception{
                try {
                        return RestResultGenerator.genSuccessResult(iWarnApi.findAll(tWarnVO));
                } catch (Exception e) {
                        return RestResultGenerator.genErrorResult("查询失败");
                }
        }


        @PostMapping("/delete/{id}")
        public Object delete(@PathVariable Integer id) throws Exception{
                try {
                        iWarnApi.delete(id);
                        return RestResultGenerator.genSuccessResult("删除成功");
                } catch (Exception e) {
                        return RestResultGenerator.genErrorResult("删除失败");
                }
        }

}
